<?
/**
 * 参数说明
 * @w 图片的宽度，默认100
 * @h 图片的高度，默认50
 *@l 验证码的长度，默认4位
 **/
Header("Content-type: image/PNG");
session_start();
unset($_SESSION['J_SafeCode_CD']);
$Len =  isset($_GET["l"]) ? $_GET["l"] : 4;
$Wid = isset($_GET["w"]) ? $_GET["w"] : 100;
$Hgt = isset($_GET["h"]) ? $_GET["h"] : 50;

$Txt = "";
//验证码的字符集中去掉数字0和字母o
$KEY = array('1','2','3','4','5','6','7','8','9',
			 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z',
			 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','p','q','r','s','t','u','v','w','x','y','z',);

$Siz = ceil(($Wid-20)/$Len);
$Img = imagecreate($Wid,$Hgt);
$Bck = ImageColorAllocate($Img , 0 , 0 , 0);
$Gry = ImageColorAllocate($Img,200,200,200);
imagefill($Img,$Wid,$Hgt,$Gry);

for($i=0;$i<$Len;$i++)
{
	$Txt.=$KEY[mt_rand(0,count($KEY)-1)];
	$Char=substr($Txt,$i,1);
	$FontColor = imageColorAllocate($Img, rand(100,255),rand(100,255),rand(100,255));
	$FontSize  = $Siz;
	$FontBody  = "./ariblk.ttf";
	$FontAngle = rand(-15,15);
	$X = 10+rand($i*$Siz,$i*$Siz-5);
	$Y = rand($FontSize,$Hgt);
 	imagettftext($Img,$FontSize,$FontAngle,$X,$Y,$FontColor,$FontBody,$Char);
}

for($i=0;$i<500;$i++)
{
	$randcolor = ImageColorallocate($Img,rand(0,255),rand(0,255),rand(0,255));
	imagesetpixel($Img, rand()%100 , rand()%100 , $randcolor);
}
$_SESSION['J_SafeCode_CD'] = $Txt;
@header("Expires: -1");
@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");
header('Content-Type: image/jpeg');
imagePNG($Img);
imageDestroy($Img);
?>